package com.lz.ccjdemo.service;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.view.accessibility.AccessibilityEvent;

public class DisablePullGestureService extends AccessibilityService {

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        if (event.getPackageName() != null && event.getPackageName().equals("com.android.launcher")) {
            if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
                // 检测到拉手势，进行拦截
                performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); // 模拟返回键操作
            }
        }
    }

    @Override
    public void onInterrupt() {
        // 在服务被中断时调用
    }

    @Override
    protected void onServiceConnected() {
        super.onServiceConnected();
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        info.eventTypes = AccessibilityEvent.TYPE_VIEW_SCROLLED;
        info.packageNames = new String[]{"com.android.launcher"};
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
        setServiceInfo(info);
    }
}
